<template>
  <div class="network-alert" v-if="!isConnected && text">
    {{ text }}
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, watch } from 'vue'
import store from '@/store'
const isConnected = ref(true)
const text = ref('')

watch(
  () => store.state.im.connectStatus,
  (status) => {
    console.log(status)
    if (status == 1) {
      isConnected.value = true
      text.value = ''
    } else if (status == 2) {
      isConnected.value = false
      text.value = '当前IM连接已断开，正在重连...'
    } else {
      isConnected.value = false
      text.value = '当前网络不可用，请检查你当前网络设置。'
    }
  },
  {
    immediate: true
  }
)
</script>

<style>
.network-alert {
  font-size: 14px;
  background: #fee3e6;
  color: #fc596a;
  text-align: center;
  padding: 8px 0;
}
</style>
